package com.bonc.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonc.common.utils.PageUtils;
import com.bonc.common.utils.Query;
import com.bonc.modules.sys.dao.SysLogDao;
import com.bonc.modules.sys.entity.SysLogEntity;
import com.bonc.modules.sys.service.SysLogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("sysLogService")
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLogEntity> implements SysLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");

        IPage<SysLogEntity> page = this.page(
                new Query<SysLogEntity>().getPage(params),
                new QueryWrapper<SysLogEntity>().like(StringUtils.isNotBlank(key), "username", key)
        );

        return new PageUtils(page);
    }

    @Autowired
    private SysLogDao sysLogDao;

    @Override
    public PageUtils queryTargetLogPage(Map<String, Object> params) {
        Page<SysLogEntity> page=new Page<SysLogEntity>(Integer.valueOf(params.get("currPage").toString()),Integer.valueOf(params.get("pageSize").toString()));
        IPage<SysLogEntity> pageMap  =this.sysLogDao.queryTargetInfoPage(page,params);
        return new PageUtils(page);
    }
}
